import "babel-polyfill";
import Vue from "vue";
import App from "./App";
import store from "./store/";
import routerMap from "./router";
import VueRouter from "vue-router";
import VueResource from "vue-resource";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import echarts from "echarts";
Vue.use(VueRouter);
Vue.use(VueResource);
Vue.use(ElementUI);
Vue.http.options.emulateJSON = true;

// 并且配置路由规则
const router = new VueRouter({
  // mode: 'hash' history,
  mode: "hash",
  base: __dirname,
  routes: routerMap
});

// 全局过滤
import filter from "./components/filter";
for (let key in filter) {
  Vue.filter(key, filter[key]);
}
// window.mapFun = new Vue();
// 路由器会创建一个 App 实例，并且挂载到选择符 #app 匹配的元素上。
const app = new Vue({
    store,
    router,
    render: h => h(App)
}).$mount('#app')
// 请求拦截
Vue.http.interceptors.push((request, next) => {
    var AccessTokenStr = ''
    if (sessionStorage.getItem('TOKEN')) {
        AccessTokenStr = sessionStorage.getItem('TOKEN')
    }
    request.headers.set('Authorization',  AccessTokenStr); //setting request.headers
    next((response) => {
        return response
    })
})
